package com.report.repository;

import com.report.entity.SubjectBalance;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SubjectBalanceRepository extends JpaRepository<SubjectBalance, Integer> {

    void deleteAllByProjectNoAndAuditCompanyUscc(String projectNo, String auditCompanyUscc);

    List<SubjectBalance> findByAccountLevelAndAuditCompanyUscc(String accountLevel, String auditCompanyUscc);

    @Query("select a from SubjectBalance a where a.accountLevel= :accountLevel and a.auditCompanyUscc=:auditCompanyUscc and a.accountCode like :accountCode%")
    List<SubjectBalance> findByAccountLevelAndAccountAndAuditCompanyUscc(String accountLevel, String accountCode, String auditCompanyUscc);

    @Query("select a from SubjectBalance a where a.accountCode like :accountCode% and a.auditCompanyUscc=:auditCompanyUscc")
    List<SubjectBalance> findByAccountCode(String accountCode, String auditCompanyUscc);


    @Query(value = "SELECT GROUP_CONCAT(account_name SEPARATOR '-') as a from subject_balance where account_code in(:accountCodes) AND audit_company_uscc=:auditCompanyUscc ORDER BY account_level", nativeQuery = true)
    String findAccountName(List accountCodes, String auditCompanyUscc);
}
